﻿function Get-TSMTables {
    <#
        .SYNOPSIS
            Get TSM DB2 tables
                    
        .DESCRIPTION
            The Get-TSMTables returns tables in DB2

        .PARAMETER TableName
            The table name to search

        .PARAMETER Schema
            The schema to search

        .EXAMPLE
            Get-TSMTables

        .NOTES
            Contributors:  David Seibel
            Last Revision Date: 09/01/2015
    #>
    [CmdletBinding()]
    Param(        
        [Parameter(Position=0)]
        $TableName,
        
        [Parameter(Position=1)]
        $Schema
    )
    
    $whereProps = @()
    $whereProps += [PSCustomObject]@{ "Column" = "TABNAME";   "Operator" = "LIKE"; "Value" = $TableName }
    $whereProps += [PSCustomObject]@{ "Column" = "TABSCHEMA"; "Operator" = "LIKE"; "Value" = $Schema }

    $query = Format-TSMQuery -Table "TABLES" -Where $whereProps -OrderBy "TABNAME"
    $result = Invoke-TSMCommand -Command $query

    $defaultDisplaySet = 'TABSCHEMA','TABNAME','CREATE_TIME'
    $typeDefinitions = @{
                        "CREATE_TIME"    = [DateTime]
                        "COLCOUNT"       = [Int32]
                        "INDEX_COLCOUNT" = [Int32]
						"UNIQUE_INDEX"   = [bool]
                        }

    return Format-TSMData -Data $result -TypeDefinitions $typeDefinitions -DefaultDisplaySet $defaultDisplaySet
}